package com.yang.controller;



import com.yang.domain.DTO.ChangeUserStatusDto;
import com.yang.domain.Result;
import com.yang.domain.entity.User;
import com.yang.service.UserService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 后台用户控制层
 * </p>
 * @author yang
 * @date 2023/5/29
 */
@RestController
@RequestMapping("/system/user")
public class UserController {

    @Resource
    private UserService userService;

    @GetMapping("/list")
    public Result list( User user, Integer pageNum, Integer pageSize){
        return userService.findUserList(user,pageNum,pageSize);
    }

    @PostMapping
    public Result add(@RequestBody User user){
       return userService.checkAndAddUser(user);
    }


    @DeleteMapping("/{userIds}")
    public Result deleteUser(@PathVariable List<Long> userIds){
        return userService.deleteUser(userIds);
    }

    @GetMapping(value = { "/{userId}" })
    public Result getUserInfo(@PathVariable(value = "userId") Long userId){
        return userService.getUserInfo(userId);
    }

    @PutMapping
    public Result updateUser(@RequestBody User user){
        return userService.updateUser(user);
    }

    @PutMapping("/changeStatus")
    public Result changeStatus(@RequestBody ChangeUserStatusDto dto){
        User user = new User();
        user.setId(dto.getUserId());
        user.setStatus(dto.getStatus());

        userService.updateUser(user);

        return Result.okResult();
    }
}
